package com.glhtgyxy.biyesheji.Controller;


import com.glhtgyxy.biyesheji.Pojo.house;
import com.glhtgyxy.biyesheji.Service.houseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;

@Controller
@RequestMapping("house")
@CrossOrigin(origins = "*")
public class houseController {

    @Autowired
    houseService service;

    @ResponseBody
    @RequestMapping("findallhouse")
    public ArrayList<house> findAllHouse(){
        System.out.println("开始查询所有房屋");
        ArrayList<house> houses = service.findAllHouse();
        System.out.println("查询所有房屋结束，返回:"+houses);
        return houses;
    }

    @ResponseBody
    @RequestMapping("findmerchanthouseandtiaojian/{addr}/{price}/{bedroom}/{search}/{id}")
    public ArrayList<house> findmerchanthouseandtiaojian(
            @PathVariable String  addr,
            @PathVariable String  price,
            @PathVariable String  bedroom,
            @PathVariable String  search,
            @PathVariable int id
    ){

        String id1=id+"";
        System.out.println("开始条件查询房屋:"+addr+price+bedroom+search+id1);
        ArrayList<house> houses = service.findmerchanthouseandtiaojian(addr,price,bedroom,search,id1);
        System.out.println("条件查询结束，返回:"+houses);
        return houses;
    }


    @ResponseBody
    @RequestMapping("findmerchanthouse/{id}")
    public ArrayList<house> findmerchantHouse(@PathVariable int id){
        System.out.println("开始查询房屋,id:"+id);
        ArrayList<house> houses = service.findmerchantHouse(id);
        System.out.println("查询房屋结束，返回:"+houses);
        return houses;
    }

    @ResponseBody
    @RequestMapping("findhouse/{searchtext}")
    public ArrayList<house> findHouse(@PathVariable String searchtext){
        System.out.println("开始查询所有房屋");
        ArrayList<house> houses = service.findHouse(searchtext);
        System.out.println("查询所有房屋结束，返回:"+houses);
        return houses;
    }

    @ResponseBody
    @RequestMapping("deletehouse/{id}")
    public boolean deleteHouse(@PathVariable int id){
        System.out.println("开始删除房屋id"+id);
        boolean houses=true;
        houses = service.deleteHouse(id);
        System.out.println("查询所有房屋结束，返回:"+houses);
        return houses;
    }



}
